package com.design.command;

import com.design.util.XMLUtil;

/**
 * @author leali
 * @title: CommandClient
 * @projectName design
 * @description: CommandClient
 * @date 2022/1/3 17:00
 */
public class CommandClient {
    public static void main(String[] args) {
        FBSettingWindow fbSettingWindow = new FBSettingWindow("功能键设置");

        FunctionButton fb1, fb2;
        fb1 = new FunctionButton("功能键1");
        fb2 = new FunctionButton("功能键1");

        Command command1, command2;
        //通过读取配置文件和反射生成具体命令对象
        command1 = (Command) XMLUtil.getValueByTagName("commandName", 0, true);
        command2 = (Command) XMLUtil.getValueByTagName("commandName", 1, true);

        //将命令对象注入功能键
        fb1.setCommand(command1);
        fb2.setCommand(command2);

        fbSettingWindow.addFunctionButton(fb1);
        fbSettingWindow.addFunctionButton(fb2);
        fbSettingWindow.display();

        //调用功能键的业务方法
        fb1.onClick();
        fb2.onClick();

        System.out.println("简易计算器测试");
        CalculatorForm form = new CalculatorForm();
        AbstractCommand command;
        command = new ConcreteCommand();
        form.setCommand(command);
        // init 0+10
        form.compute(10);
        form.compute(5);
        form.compute(10);
        // 补鞥呢实现多次撤销
        form.undo();
        form.undo();
        form.undo();

        System.out.println("网络命令测试");
        ConfigSettingWindow csw = new ConfigSettingWindow();
        NetCommand netCommand; //定义命令对象
        ConfigOperator co = new ConfigOperator();

        //四次对配置文件的更改
        netCommand = new InsertNetCommand("增加");
        netCommand.setConfigOperator(co);
        csw.setNetCommand(netCommand);
        csw.call("网站首页");

        netCommand = new InsertNetCommand("增加");
        netCommand.setConfigOperator(co);
        csw.setNetCommand(netCommand);
        csw.call("端口号");

        netCommand = new ModifyNetCommand("修改");
        netCommand.setConfigOperator(co);
        csw.setNetCommand(netCommand);
        csw.call("网站首页");

        netCommand = new ModifyNetCommand("修改");
        netCommand.setConfigOperator(co);
        csw.setNetCommand(netCommand);
        csw.call("端口号");

        System.out.println("----------------------------");
        System.out.println("保存配置");
        csw.save();

        System.out.println("----------------------------");
        System.out.println("恢复配置");
        System.out.println("----------------------------");
        csw.recover();
    }
}
